package com.whfc.wxmp.api.fmam.service.impl;


import com.whfc.fmam.service.FmamWeighRoomService;
import com.whfc.fvs.dto.FvsDeviceDTO;
import com.whfc.fvs.enums.FvsBizType;
import com.whfc.fvs.param.FvsDeviceListParam;
import com.whfc.fvs.service.FvsDeviceService;
import com.whfc.wxmp.api.fmam.service.WxFmamDeviceService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 * @author: qzexing
 * @version: 1.0
 * @date: 2020/4/11 20:01
 */
@Service
public class WxFmamDeviceServiceImpl implements WxFmamDeviceService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    private String ossImgProcess = "?x-oss-process=image/quality,q_75/resize,m_lfit,h_300,w_500";

    @DubboReference(interfaceClass = FmamWeighRoomService.class, version = "1.0.0")
    private FmamWeighRoomService fmamWeighRoomService;

    @DubboReference(interfaceClass = FvsDeviceService.class, version = "1.0.0")
    private FvsDeviceService fvsDeviceService;

    @Override
    public List<FvsDeviceDTO> selectDeviceList(Integer deptId) {
        List<Integer> weighRoomIds = fmamWeighRoomService.listWeighRoomId(deptId);
        logger.info("获取磅房ID列表，weighRoomIds：{}", weighRoomIds);
        FvsDeviceListParam fvsDeviceListParam = new FvsDeviceListParam();
        fvsDeviceListParam.setDeptId(deptId);
        fvsDeviceListParam.setBizType(FvsBizType.FMAM.getValue());
        fvsDeviceListParam.setWeighRoomIds(weighRoomIds);
        List<FvsDeviceDTO> deviceList = fvsDeviceService.listWeighRoomDevice(fvsDeviceListParam);
        for (FvsDeviceDTO appFvsDTO : deviceList) {
            String snapshotUrl = appFvsDTO.getSnapshotUrl();
            if (StringUtils.isNotEmpty(snapshotUrl)) {
                appFvsDTO.setSnapshotUrl(snapshotUrl + ossImgProcess);
            }
        }
        return deviceList;
    }
}
